package com.jsbb.controller.sys;

import com.jsbb.annotation.ApiLog;
import com.jsbb.common.Message;
import com.jsbb.dto.sys.SysMenuQueryDto;
import com.jsbb.dto.sys.SysMenuSaveDto;
import com.jsbb.dto.sys.SysMenuUpdateDto;
import com.jsbb.service.sys.SysMenuService;
import com.jsbb.vo.sys.SysMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单管理Controller
 *
 * @author w
 * @date 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/sys/menu")
@ApiLog("菜单管理")
@Api(tags = {"2.3 系统管理-菜单管理"})
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @PostMapping("/list")
    @ApiOperation(value = "获取列表")
    public Message<List<SysMenuVo>> list(@Validated @RequestBody SysMenuQueryDto queryDto) {
        List<SysMenuVo> list = sysMenuService.list(queryDto);
        return Message.success(list);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取详情")
    public Message<SysMenuVo> get(@PathVariable("id") Long id) {
        SysMenuVo menuVo = sysMenuService.get(id);
        return Message.success(menuVo);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增")
    public Message save(@Validated @RequestBody SysMenuSaveDto saveDto) {
        sysMenuService.save(saveDto);
        return Message.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Message update(@Validated @RequestBody SysMenuUpdateDto updateDto) {
        sysMenuService.update(updateDto);
        return Message.success();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public Message delete(@PathVariable("id") Long id) {
        sysMenuService.delete(id);
        return Message.success();
    }

//    @GetMapping("/get/{userId}")
//    @ApiOperation(value = "获取用户权限")
//    public Message<List<SysMenuVo>> getPermission(@PathVariable("userId") Long userId) {
//        List<SysMenuVo> list = sysMenuService.selectByUserId(userId);
//        return Message.success(list);
//    }
}
